/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import javax.swing.JOptionPane;
import src.Core;

/**
 *
 * @author Strauzen
 */
public class VentanaColectivo extends javax.swing.JFrame {

    Ventana1 v1;
    Ventana3 v3;
    
    /**
     * Creates new form VentanaColectivo
     */
    public VentanaColectivo(Ventana1 v1, Ventana3 v3) {
        this.v1 = v1;
        this.v3 = v3;
        initComponents();
    }

    private boolean comprobar(){
        String mensaje = "";
        boolean resultado = false;
        
        if (this.jTextField_vcoNombre.getText().equals(""))
            mensaje += "Por favor rellene el campo de nombre\n\n";
        if (this.jTextField_vcoDescripcion.getText().equals(""))
            mensaje += "Por favor rellene el campo de descripción\n\n";
 
        if ("".equals(mensaje))
            resultado =true;
        else
            JOptionPane.showMessageDialog(null, mensaje);
        
        return resultado;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vcoNombre = new javax.swing.JLabel();
        jTextField_vcoNombre = new javax.swing.JTextField();
        jLabel_vcoDescripcion = new javax.swing.JLabel();
        jTextField_vcoDescripcion = new javax.swing.JTextField();
        jButton_vcoFichero = new javax.swing.JButton();
        jButton_vcoTerminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel_vcoNombre.setText("Nombre");

        jLabel_vcoDescripcion.setText("Descripcion");

        jButton_vcoFichero.setText("Añadir Ficheros");
        jButton_vcoFichero.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vcoFicheroMouseClicked(evt);
            }
        });

        jButton_vcoTerminar.setText("Terminar");
        jButton_vcoTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vcoTerminarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vcoNombre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vcoNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vcoDescripcion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vcoDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 329, Short.MAX_VALUE)
                .addComponent(jButton_vcoFichero))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(178, 178, 178)
                .addComponent(jButton_vcoTerminar)
                .addContainerGap(183, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vcoNombre)
                    .addComponent(jTextField_vcoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vcoDescripcion)
                    .addComponent(jTextField_vcoDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_vcoFichero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_vcoTerminar)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_vcoFicheroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vcoFicheroMouseClicked
        // TODO add your handling code here:
        this.setVisible(false);
        Ventana4 v4 = new Ventana4(v1,v3);
        v4.setVisible(true);
        v4.setPadre(6);
        v4.setVco(this);
    }//GEN-LAST:event_jButton_vcoFicheroMouseClicked

    private void jButton_vcoTerminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vcoTerminarMouseClicked
        // TODO add your handling code here:
        if(comprobar()){
            this.setVisible(false);
            v3.setVisible(true);
            int c = Core.CrearColectivo(jTextField_vcoNombre.getText(), jTextField_vcoDescripcion.getText());
            Core.linkaColectivoConDocumento(Core.getDocumento(),c);
            this.dispose();
        }
    }//GEN-LAST:event_jButton_vcoTerminarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vcoFichero;
    private javax.swing.JButton jButton_vcoTerminar;
    private javax.swing.JLabel jLabel_vcoDescripcion;
    private javax.swing.JLabel jLabel_vcoNombre;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vcoDescripcion;
    private javax.swing.JTextField jTextField_vcoNombre;
    // End of variables declaration//GEN-END:variables
}
